package com.cyq.day05;

import java.util.Scanner;

public class HomeWork {
    public static void main(String[] args) {
        homework01();
        homework02();
        homework03();
    }

    public static void homework01() {
        //输入7位同学的成绩，找出最高分最低分
        Scanner sc = new Scanner(System.in);
        int[] arr = new int[7];
        for (int i = 1; i < 8; i++) {
            System.out.println("请输入第" + i + "位同学的成绩");
            int score = sc.nextInt();
            arr[i - 1] = score;
        }
        for (int i = 0; i < arr.length - 1; i++) {
            for (int j = 0; j < arr.length - 1 - i; j++) {
                if (arr[j] > arr[j + 1]) {
                    int temp = arr[j];
                    arr[j] = arr[j + 1];
                    arr[j + 1] = temp;
                }
            }
        }
        System.out.println("最高分为：" + arr[arr.length - 1]);
        System.out.println("最低分为" + arr[0]);

    }

    public static void homework02() {
        //给定一个数组，编写程序对该数组元素进行去重
        int[] arr = {2, 2, 1, 5, 6, 2, 3, 7, 3, 1, 2, 5, 6, 3, 7};
        //创建新数组用于存放结果
        int[] arr1 = new int[arr.length];
        int index=0;
        for (int i=0;i<arr.length;i++){
            boolean flag=true;
            for (int j=0;j<index;j++){
                if (arr[i]==arr[j]){
                    flag=false;
                    break;
                }
            }
            if (flag){
                arr1[index]=arr[i];
                index++;
            }
        }
        for (int i=0;i<index;i++){
            System.out.println(arr1[i]);
        }
    }

    public static void homework03() {
        //双色球：系统随机生产一个中奖号码，红球范围1-33，篮球范围1-16
        //6个红球不能重复，蓝球可以和红球的值相同
        //用户输入一组双色球号码，然后和系统产生的号码进行比较，给出比较的结果
        //中奖规则：
        //一等奖6+1;二等奖6+0;三等奖5+1;四等奖5+0或4+1;五等奖4+0或者3+1;六等奖1蓝球相符合
        //生成号码
        int[] number = new int[7];
        for (int i = 0; i < number.length - 1; i++) {
            int index = (int) (Math.random() * 33 + 1);
            number[i] = index;
            //保证红色号码不重复
            for (int j = 0; j < i; j++) {
                if (number[i] == number[j]) {
                    i--;
                    break;
                }
            }
        }
        number[6] = (int) (Math.random() * 16 + 1);
        System.out.print("本期开奖号码为：");
        for (int i : number
        ) {
            System.out.print(i + " ");
        }
        //用户输入
        Scanner sc = new Scanner(System.in);
        int[] userNumber = new int[7];
        System.out.println();
        System.out.println("请输入您的双色球7位号码，先输入6位红色球号码，再输入一位蓝色球号码");
        for (int i = 0; i < number.length; i++) {
            System.out.println("请输入第" + (i + 1) + "位球号码");
            userNumber[i] = sc.nextInt();
        }
        //判断中奖
        System.out.println("开奖结果为：");
        int redFlag = 0;
        int blueFlag = 0;
        for (int i=0;i<6;i++){
            for (int j=0;j<6;j++){
                if (number[i]==userNumber[j]){
                    redFlag++;
                    break;
                }
            }
        }
        if (number[6] == userNumber[6]) {
            blueFlag++;
        }
        switch (redFlag) {
            case 6:
                if (blueFlag==1){
                    System.out.println("恭喜你一等奖");
                }else{
                    System.out.println("恭喜你二等奖");
                }
                break;
            case 5:
                if (blueFlag==1){
                    System.out.println("恭喜你三等奖");
                }else{
                    System.out.println("恭喜你四等奖");
                }
                break;
            case 4:
                if (blueFlag==1){
                    System.out.println("恭喜你四等奖");
                }else{
                    System.out.println("恭喜你五等奖");
                }
                break;
            case 3:
                if (blueFlag==1){
                    System.out.println("恭喜你五等奖");
                }
                break;
            case 2:
            case 1:
            case 0:
                if (blueFlag==1){
                    System.out.println("恭喜你六等奖");
                }
                break;
            default:
                System.out.println("很遗憾你没有中将");
        }

    }
}
